package org.hxzon.demo.scala.matchdemo

object ListMatch {
  def processItems(items: List[String]) {
    items match {
      case List("apple", "ibm") => println("Apples and IBMs")
      case List("red", "blue", "white") => println("Stars and Stripes...")
      case List("red", "blue", _*) => println("colors red,blue,...")
      case List("apple", "orange", otherFruits @ _*) => println("apples,oranges,and " + otherFruits)
      case Nil => null
      case _ => println(items)
    }
  }
  def main(args: Array[String]): Unit = {
    processItems(List("apple", "ibm")) //Apples and IBMs
    processItems(List("red", "blue", "green")) //colors red,blue,...
    processItems(List("red", "blue", "white")) //Stars and Stripes...
    processItems(List("apple", "orange", "grapes", "dates")) //apples,oranges,and List(grapes, dates)
    processItems(Nil) //nothing
    //processItems(List(1,2,3))//compiler error
  }
}
